Adding a single value in list is quite generic and easy. But to add that value more than one time, generally, a loop is used to execute this task. Having shorter tricks to perform this can be handy. Let’s discuss certain ways in which this can be done....
Given List of tuples, filter tuples that have same values....
Given a list ‘L’, a sum ‘S’ and number of elements to take at a time ‘m’. The task is to find how many ways sum s can be found by adding any m contiguous elements. Examples:...
We often come to the situations in which we need to extract initial K elements of list. This particular problem occurs when we need to optimize memory. This has its application in the day-day programming when sometimes we require to get all the lists of similar size. Let’s discuss certain ways in which this task can be performed. Method #1 : Using len() + list slicing List slicing can perform this particular task in which we just slice the first K elements to be in the list and hence removing the remaining elements, freeing memory....
Given List of tuples, find index-wise absolute difference of consecutive tuples....
The usual list of list, unlike conventional C type Matrix, can allow the nested list of lists with variable lengths, and when we require the maximizations of its columns, the uneven length of rows may lead to some elements in that elements to be absent and if not handled correctly, may throw an exception. Let’s discuss certain ways in which this problem can be performed in an error-free manner....
Given a list, remove all the occurrence of y before element x in list....
Printing the list has been dealt many times. But sometimes we need a different format to get the output of list. This also has application in getting a transpose of matrix. Printing list vertically also has application in web development. Lets discuss certain ways in which this task can be achieved....
Sometimes, we might be working with many data types and in these instances, we can have a problem in which list that we receive might be having elements from different data types. Let’s discuss certain ways in which this task can be performed....
Given a list of lists, the task is to multiply each element in a sublist by its index and return a summed list. Given below are a few methods to solve the problem....
Given a String, extract all the numbers that are percentages....
Sometimes, while working with data, we can have a problem in which we receive mixed data and need to convert the integer elements in form of strings to integers. This kind of operation might be required in data preprocessing step. Let’s discuss certain ways in which this task can be performed....